 <template>
   <Card :shadow="shadow">
      <div class="card-name">
        <div class="name width1">人工订单</div>
      </div>
      <div class="content-con">
        <Form>
          <Row :gutter="24" type="flex" justify="end" class="code-row-bg">
            <Col span="4">
              <FormItem>
                <i-select :model.sync="model1" style="color: #000;" placeholder="时间段">
                    <i-option v-for="item in timeList" :value="item.value">{{ item.label }}</i-option>
                </i-select>
              </FormItem>
            </Col>
            <Col span="4">
              <FormItem>
                <Date-picker style="width: 100%;" type="datetime" placeholder="开始时间"></Date-picker>
              </FormItem>
            </Col>
            <Col span="4">
              <FormItem>
                <Date-picker style="width: 100%;" type="datetime" placeholder="结束时间"></Date-picker>
              </FormItem>
            </Col>
            <Col span="4">
              <FormItem>
                <i-input :value.sync="value" placeholder="商户ID"></i-input>
              </FormItem>
            </Col>
            <Col span="4">
              <FormItem>
                <i-input :value.sync="value" placeholder="账户名"></i-input>
              </FormItem>
            </Col>
          </Row>
          <Row :gutter="24" type="flex" justify="end" class="code-row-bg">
            <Col span="4">
              <FormItem>
                <i-input :value.sync="value" placeholder="代付单号"></i-input>
              </FormItem>
            </Col>
            <Col span="4">
              <FormItem>
                <i-input :value.sync="value" placeholder="受理人"></i-input>
              </FormItem>
            </Col>
            <Col span="4">
              <FormItem>
                <i-input :value.sync="value" placeholder="转账单号"></i-input>
              </FormItem>
            </Col>
            <Col span="4">
              <FormItem>
                <i-select :model.sync="model2" style="color: #000;" placeholder="代付渠道">
                    <i-option v-for="item in insteadList" :value="item.value">{{ item.label }}</i-option>
                </i-select>
              </FormItem>
            </Col>
            <Col span="4">
              <FormItem>
                <i-select :model.sync="model3" style="color: #000;" placeholder="状态">
                    <i-option v-for="item in statuList" :value="item.value">{{ item.label }}</i-option>
                </i-select>
              </FormItem>
            </Col>
          </Row>
          <FormItem class="btn-search">
            <i-button size="large" class="btn-green">搜索</i-button>
          </FormItem>
        </Form>
        <div class="capital-money">
          <div class="capital-money-item">
            订单数：<span class="list1">21</span>
            代付金额：<span class="list1">¥9580</span>
            代付费用：<span class="list2">¥19</span>
            扣减金额：<span class="list2">¥9599</span>
          </div>
        </div>
        <div class="bank-form">
          <div class="form-item">
            <i-table :columns="foodColumns" :data="foodData"></i-table> <!-- table组件 -->
          </div>
          <div class="page">
            <Page :id="pageId"
             :total="dataCount"
             :page-size="pageSize"
             style="float: left;"
             @on-change="changepage"
             @on-page-size-change="nowPageSize"
             show-total show-sizer show-elevator></Page> <!-- page组件 -->
            <Button style="float: left;margin-left: 10px;" type="primary" @click="goElevatorPage">确认</Button>
          </div>
        </div>
      </div>
   </Card>

 </template>
<script>

let testData = {
  histories: [
    {
      merchantId: '20000031',
      transferId: 'T01202009281653022990048',
      accountName: '张三',
      accountId: '1234',
      insteadAmount: '200',
      fee: '1',
      subAmount: '201',
      status: '待处理',
      instead: '商户后台',
      time: '2020-09-28 16:53:02'
    },
    {
      merchantId: '20000031',
      transferId: 'T01202009281653022990048',
      accountName: '张三',
      accountId: '1234',
      insteadAmount: '200',
      fee: '1',
      subAmount: '201',
      status: '待处理',
      instead: '商户后台',
      time: '2020-09-28 16:53:02'
    },
    {
      merchantId: '20000031',
      transferId: 'T01202009281653022990048',
      accountName: '张三',
      accountId: '1234',
      insteadAmount: '200',
      fee: '1',
      subAmount: '201',
      status: '待处理',
      instead: '商户后台',
      time: '2020-09-28 16:53:02'
    }
  ]
}
export default {
  name: 'artificial_order',
  props: {
    shadow: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      value: '',
      pageId: 'targetpage',
      ajaxHistoryData: [],
      exportdata: [],
      // 初始化信息总条数
      dataCount: 0,
      // 每页显示多少条
      pageSize: 10,
      pageCurrent: 1, // 当前页
      foodColumns: [
        {
          type: 'selection',
          width: 60,
          align: 'center',
          fixed: 'left'
        },
        {
          title: '商户ID/商户名',
          key: 'merchantId',
          width: 140
        },
        {
          title: '转账单号',
          key: 'transferId',
          width: 190
        },
        {
          title: '账户名',
          key: 'accountName',
          width: 120
        },
        {
          title: '账号',
          key: 'accountId',
          width: 120
        },
        {
          title: '代付金额(元)',
          key: 'insteadAmount',
          width: 120
        },
        {
          title: '手续费(元)',
          key: 'fee',
          width: 120
        },
        {
          title: '扣减账户金额(元)',
          key: 'subAmount',
          width: 120
        },
        {
          title: '状态',
          key: 'status',
          width: 120
        },
        {
          title: '代付渠道',
          key: 'instead',
          width: 130
        },
        {
          title: '时间',
          key: 'time',
          width: 160
        },
        {
          title: '操作',
          key: 'action',
          width: 130,
          align: 'center',
          render: (h, params) => {
            return h('div', [
              h(
                'Button', {
                  props: {
                    size: 'small'
                  },
                  style: {
                    color: 'white',
                    padding: '0 5px',
                    height: '24px',
                    fontSize: '12px',
                    backgroundColor: '#009688'
                  },
                  on: {
                    click: () => {
                      this.$router.push({
                        name: 'artifcial-order-details'
                      })
                    }
                  }
                },
                '详情'
              )
            ])
          }
        }
      ],
      foodData: [],
      timeList: [
        {
          value: 'beijing',
          label: '时间段'
        },
        {
          value: 'shanghai',
          label: '当日'
        },
        {
          value: 'shenzhen',
          label: '昨日'
        },
        {
          value: 'hangzhou',
          label: '半月'
        },
        {
          value: 'nanjing',
          label: '当月'
        }
      ],
      model1: '',
      insteadList: [
        {
          value: 'beijing',
          label: '代付渠道'
        },
        {
          value: 'shanghai',
          label: '商户后台'
        },
        {
          value: 'shenzhen',
          label: 'API接口'
        }
      ],
      model2: '',
      statuList: [
        {
          value: 'being',
          label: '状态'
        },
        {
          value: 'beijing',
          label: '待处理'
        },
        {
          value: 'shanghai',
          label: '处理中'
        },
        {
          value: 'shhen',
          label: '成功'
        },
        {
          value: 'sen',
          label: '失败'
        },
        {
          value: 'en',
          label: '回退'
        }
      ],
      model3: ''
    }
  },
  methods: {
    // 获取历史记录信息
    handleListApproveHistory () {
      // 保存取到的所有数据
      this.ajaxHistoryData = testData.histories
      this.exportdata = testData.histories
      this.dataCount = testData.histories.length
      // 初始化显示，小于每页显示条数，全显，大于每页显示条数，取前每页条数显示
      if (testData.histories.length < this.pageSize) {
        this.foodData = this.ajaxHistoryData
      } else {
        this.foodData = this.ajaxHistoryData.slice(0, this.pageSize)
      }
    },
    // 点击切换页面
    changepage (index) {
      // 需要显示开始数据的index,(因为数据是从0开始的，页码是从1开始的，需要-1)
      let _start = (index - 1) * this.pageSize
      // 需要显示结束数据的index
      let _end = index * this.pageSize
      // 截取需要显示的数据
      this.foodData = this.ajaxHistoryData.slice(_start, _end)
      // 储存当前页
      this.pageCurrent = index
    },
    // 每页显示的数据条数
    nowPageSize (index) {
      let _start = (this.pageCurrent - 1) * index
      let _end = this.pageCurrent * index
      this.foodData = this.ajaxHistoryData.slice(_start, _end)
      // 实时获取当前需要显示的条数
      this.pageSize = index
    },

    // 点击确认，跳转到输入的页码
    goElevatorPage () {
      var evtObj
      var thisPage = document.getElementById(this.pageId)
      // var thisPage=this.$refs.myPage;//也可以用ref来获取page这个dom
      var elevatorDiv = thisPage.getElementsByClassName('ivu-page-options-elevator')
      // 如果thisPage这里报错了,请核对上文的获取page的DOM的语句是否获取不到
      if (elevatorDiv && elevatorDiv.length > 0) {
        var pageInput = elevatorDiv[0].getElementsByTagName('input')[0]
        if (window.KeyEvent) { // firefox 浏览器下模拟事件
          evtObj = document.createEvent('KeyEvents')
          evtObj.initKeyEvent('keyup', true, true, window, true, false, false, false, 13, 0)
        } else { // chrome 浏览器下模拟事件
          evtObj = document.createEvent('UIEvents')
          evtObj.initUIEvent('keyup', true, true, window, 1)
          delete evtObj.keyCode
          if (typeof evtObj.keyCode === 'undefined') { // 为了模拟keycode
            Object.defineProperty(evtObj, 'keyCode', { value: 13 })
          } else {
            evtObj.key = String.fromCharCode(13)
          }
        }
        pageInput.dispatchEvent(evtObj)
      }
    }
  },
  created () {
    this.handleListApproveHistory()
  }
}
</script>
 <style lang="less">
 </style>
